Repository navigation
fix(cli): read the semicolon from raw SQL in the remote confirm check - #869
Merged
Merged
Conversation
`SELECT '--' ; DROP TABLE users` was stripped as a comment, so the check saw one SELECT and sent the DROP without the confirmation prompt. Read the semicolon from the raw text, where a literal cannot hide it, and keep comment stripping for the read-only prefix test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The remote
void db executeconfirmation prompt is meant to fail closed. Only a single read-only statement skips it, and the semicolon test ran on text with comments stripped, so a literal could hide a second statement.void db execute --remote "SELECT '--' ; DROP TABLE t"was cut at the--, read as one SELECT, and sent without the prompt.The semicolon is now read from the raw SQL, minus a trailing one, so a literal cannot hide it. Comment stripping stays for the read-only prefix test, which keeps
-- header\nSELECT 1prompt-free andEXPLAIN ANALYZEprompting. A semicolon inside a comment or a literal now costs one extra prompt, which is the safe side of that trade.Test
db-execute-remote.test.tsruns the prompt in a TTY. The new cases assert thatSELECT '--' ; DROP TABLE users,SELECT '/*' ; DROP TABLE usersand-- a; comment\nSELECT 1prompt, whileSELECT 1;andSELECT '--'do not.